<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /* @var $this \Magento\Paypal\Block\Billing\Agreements */ ?>
<div class="account-billing-agreements">
    <?php $billingAgreements = $this->getBillingAgreements(); ?>
    <?php if (count($billingAgreements) > 0): ?>
        <?php echo $this->getChildHtml('pager'); ?>
        <div class="table-wrapper billing-agreements">
            <table id="billing-agreements" class="data table table-billing-agreements">
                <caption class="table caption"><?php echo __('Billing Agreements') ?></caption>
                <thead>
                <tr>
                    <th scope="col" class="col id"><?php echo __('Reference ID'); ?></th>
                    <th scope="col" class="col status"><?php echo __('Status'); ?></th>
                    <th scope="col" class="col created"><?php echo __('Created At'); ?></th>
                    <th scope="col" class="col updated"><?php echo __('Updated At'); ?></th>
                    <th scope="col" class="col payment"><?php echo __('Payment Method'); ?></th>
                    <th scope="col" class="col actions">&nbsp;</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($billingAgreements as $item): ?>
                    <tr>
                        <td data-th="<?php echo $this->escapeHtml(__('Reference ID')); ?>" class="col id"><?php echo $this->getItemValue($item, 'reference_id') ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Status')); ?>" class="col status"><?php echo $this->getItemValue($item, 'status') ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Created At')); ?>" class="col created"><?php echo $this->getItemValue($item, 'created_at') ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Updated At')); ?>" class="col updated"><?php echo $this->getItemValue($item, 'updated_at') ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Payment Method')); ?>" class="col payment"><?php echo $this->getItemValue($item, 'payment_method_label') ?></td>
                        <td data-th="" class="col actions">
                            <a href="<?php echo $this->getItemValue($item, 'edit_url') ?>" class="action view"><span><?php echo __('View') ?></span></a>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <div class="message info empty"><span><?php echo __('There are no billing agreements yet.') ?></span></div>
    <?php endif; ?>

    <?php $paymentMethods = $this->getWizardPaymentMethodOptions() ?>
    <?php if ($paymentMethods): ?>
        <form action="<?php echo $this->getCreateUrl() ?>" method="post" class="form form-new-agreement">
            <fieldset class="fieldset">
                <legend class="legend"><span><?php echo __('New Billing Agreement') ?></span></legend>
                <br />
                <p class="note"><?php echo __('You will be redirected to the payment system website.') ?></p>

                <div class="field payment method">
                    <div class="control">
                        <select id="payment_method" name="payment_method">
                            <option value=""><?php echo __('-- Please Select --') ?></option>
                            <?php foreach ($paymentMethods as $code => $title): ?>
                                <option value="<?php echo $code ?>"><?php echo $title ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="actions-toolbar">
                    <div class="primary">
                        <button type="submit" class="primary action create">
                            <span><?php echo __('Create...') ?></span>
                        </button>
                    </div>
                    <div class="secondary">
                        <a href="<?php echo $this->escapeHtml($this->getBackUrl()) ?>"
                           class="action back"><span><?php echo __('Back') ?></span></a>
                    </div>
                </div>
            </fieldset>
        </form>
    <?php else: ?>
    <div class="actions-toolbar">
        <div class="secondary">
            <a href="<?php echo $this->escapeHtml($this->getBackUrl()) ?>"
               class="action back"><span><?php echo __('Back') ?></span></a>
        </div>
    </div>
    <?php endif; ?>
</div>
